package entities;

import java.io.Serializable;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;

@Entity
@Table(name = "Tache")
public class Tache implements Serializable {

    private Long id_tache;
    private Utilisateur responsable;
    private List<Utilisateur> participants;
    private String description;
    private String titre;
    private List<Document> documents;
    private List<Message> messages;
    private List<Avis> avis;
    private Date dateCreation;
    private Date dateFin;

    public Tache() {
        this.dateCreation = new Date();
        this.participants = new ArrayList<>();
        this.documents = new ArrayList<>();
        this.messages = new ArrayList<>();
        this.avis = new ArrayList<>();
    }

    public Tache(String titre, String description, Date dateFin, Utilisateur responsable) {
        this.titre = titre;
        this.description = description;
        this.dateFin = dateFin;
        this.responsable = responsable;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id_tache;
    }

    public void setId(Long id_tache) {
        this.id_tache = id_tache;
    }

    @JoinColumn(name = "RESPONSABLE", nullable = false, updatable = false)
    @ManyToOne
    public Utilisateur getResponsable() {
        return responsable;
    }

    public void setResponsable(Utilisateur responsable) {
        this.responsable = responsable;
    }

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "participations")
    public List<Utilisateur> getParticipants() {
        return participants;
    }

    public void setParticipants(List<Utilisateur> participants) {
        this.participants = participants;
    }

    @Size(min = 1, max = 2000)
    @Column(name = "DESCRIPTION")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Size(min = 1, max = 100)
    @Column(name = "TITRE", nullable = false)
    public String getTitre() {
        return titre;
    }

    public void setTitre(String titre) {
        this.titre = titre;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "DATE_CREATION", nullable = false, updatable = false)
    public Date getDateCreation() {
        return dateCreation;
    }

    public void setDateCreation(Date dateCreation) {
        this.dateCreation = dateCreation;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "DATE_FIN", nullable = false)
    public Date getDateFin() {
        return dateFin;
    }

    public void setDateFin(Date dateFin) {
        this.dateFin = dateFin;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tache")
    public List<Document> getDocuments() {
        return documents;
    }

    public void setDocuments(List<Document> documents) {
        this.documents = documents;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tache")
    public List<Message> getMessages() {
        return messages;
    }

    public void setMessages(List<Message> messages) {
        this.messages = messages;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tache")
    public List<Avis> getAvis() {
        return avis;
    }

    public void setAvis(List<Avis> avis) {
        this.avis = avis;
    }

}
